package com.xiaoma.lock.condition.usecase;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

public class ConditionWait implements Runnable {

  private ReentrantLock lock;
  private Condition condition;

  public ConditionWait(ReentrantLock lock, Condition condition) {
    this.lock = lock;
    this.condition = condition;
  }


  @Override
  public void run() {
    try {
      lock.lock();
      System.out.println("开始wait");
      condition.wait();
      System.out.println("结束wait");
    } catch (InterruptedException e) {
      e.printStackTrace();
    } finally {
      lock.unlock();
    }
  }

}
